/*
 * @(#)ProgressRenderer.java
 */
package com.pluginsacceptor.acceptor.ui.info;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import org.apache.log4j.Logger;

import com.pluginsacceptor.acceptor.activator.PluginList;

/**
 *
 * Progress renderer
 */
public class PluginInfoRenderer extends DefaultTableCellRenderer {

    /** Logger */
    private static final Logger LOG = Logger.getLogger(PluginInfoRenderer.class);

    /** */
    private final JButton del = new JButton("Del");

    public PluginInfoRenderer(final JTable table) {
      super();
      setOpaque(true);
      del.setBorder(BorderFactory.createEmptyBorder(1,1,1,1));
      del.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent arg0) {
                PluginList.getActivePlugins().remove(table.getSelectedRow());
                LOG.debug("removed row" + table.getSelectedRow());
//                table.setModel(PluginInfoFrame.refillTableModel());
            }
          }
      );
    }

    @Override
    public Component getTableCellRendererComponent(
       final JTable table,
       final Object value,
       final boolean isSelected,
       final boolean hasFocus,
       final int row,
       final int column
  ) {

        return (column == PluginInfoFrame.DEL_BUTTON_POS) ? (JButton) value
            : super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }
}
